<template>
  	<div id="app">
  		
		<view-box ref="viewBox"
			:body-padding-bottom="$route.meta.showTabbar?'50px':0"
			:body-padding-top="$route.meta.showTitle?'46px':0">
	        <app-header></app-header>

		    <transition
		    @after-enter="$zq.bus && $zq.bus.$emit('vux:after-view-enter')" 
		    :name="'vux-pop-' + (direction === 'forward' ? 'in' : 'out')">
		      <router-view class="router-view"></router-view>
		    </transition>

		    <app-footer></app-footer>
		</view-box>
	</div>
</template>

<script>
import {ViewBox } from 'vux'
import{Loading} from 'vant'
import AppHeader from 'view/header';
import AppFooter from 'view/footer';
import { mapState, mapActions } from 'vuex'
export default {
	name: 'app',
	data() {
		return {
		}
	},
	components: {
		AppHeader,AppFooter,
		ViewBox,
		[Loading.name]: Loading,
  	},
  	computed: {
	    ...mapState({
	      isLoading: state => state.isLoading,
	      direction: state => state.direction
	    }),
	    headerTransition () {
	      return this.direction === 'forward' ? 'vux-header-fade-in-right' : 'vux-header-fade-in-left'
	    },
  	},
	methods: {	
		checkAppUpdate(showText){
			if(window.plus){
				checkAppUpdate().then(data=>{
					this.$native.getAppVersion().then(version=>{
						let url='/file/downloadController/getFile.do',self=this;
						if(data.obj.version>version){
							if(data.obj.key==1){
								url='https://bdxccs.gzkit.com.cn:8013'+data.obj.name;
							}
							plus.nativeUI.showWaiting("正在下载更新文件...");
							let dtask=plus.downloader.createDownload(url, {
								filename: "_doc/update/"
							}, function(d, status) {
								if(status == 200) {
									console.log("下载wgt成功：" + d.filename);
									self.$native.installWgt(d.filename);
								} else {
									console.log("下载wgt失败！");
									plus.nativeUI.alert("下载更新文件失败！");
								}
								plus.nativeUI.closeWaiting();
							})
							dtask.start();
						}else{
							showText&&self.$toast("已经是最新版本了！");
						}
						
					})
				}).catch(err=>{
					console.log(err)
				})		
			}
		}
			
	},
	created() {
		let _this = this;
		//app后退按键
		document.addEventListener("backmonitor", function() {
			if(_this.$router.history.current.meta.exitApp){
				if(_this.exitFlag)
					_this.$native.exitApp();
				else{
					_this.$toast("连按两下将退出应用");
					_this.exitFlag = true;
					setTimeout(function(){
						_this.exitFlag = false;
					},500)
				}
			}	
			else{
				_this.$router.back();
			}
				
		})
		
				
	},
	mounted() {
		window.hideLoadingPage();
		// console.log(this)
		// shop.getList()
		 	
	},		
}
</script>

<style lang="less">
@import '~vux/src/styles/reset.less';
@import 'style/base.less';
@import 'style/layout.less';
@import url("//at.alicdn.com/t/font_519423_1ikmr0z3fas8aor.css");
// @import 'vant/lib/vant-css/index.css';

</style>
